<template lang="">
  <div class="centent"> 

  <el-container>
      <el-header>
        <span>后台管理系统</span>
        <el-button type="primary" @click="tologin" v-if="!data.isLoggedIn">登录</el-button> 
        <el-button type="primary" @click="tooutlogin" v-if="data.isLoggedIn">退出</el-button> 
        <!-- <el-button type="primary" @click="toLink">点击跳转</el-button>  -->
      </el-header>
  <el-container>
  <el-aside width="200px">
  <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
    <el-radio-button :label="false">展开</el-radio-button>
    <el-radio-button :label="true">隐藏</el-radio-button>
  </el-radio-group>
  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    :collapse="isCollapse"
    @open="handleOpen"
    @close="handleClose"
  >
    <el-sub-menu index="1">
      <template #title>
        <el-icon><location /></el-icon>
        <span>位置</span>
      </template>
      <el-menu-item-group>
        <template #title><span>项目一</span></template>
        <el-menu-item index="1-1">项目1-1</el-menu-item>
        <el-menu-item index="1-2">项目1-2</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="项目二">
        <el-menu-item index="1-3">项目2-3</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="1-4">
        <template #title><span>项目2-4</span></template>
        <el-menu-item index="1-4-1">项目3-1</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
    <el-menu-item index="2">
      <el-icon><icon-menu /></el-icon>
      <template #title>分类二</template>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <el-icon><document /></el-icon>
      <template #title>分类三</template>
    </el-menu-item>
    <el-menu-item index="4">
      <el-icon><setting /></el-icon>
      <template #title>分类四</template>
    </el-menu-item>
  </el-menu>
  </el-aside>
        <el-main>

<App>
  <template v-slot:header>
    <h1>这是头部内容</h1>
  </template>
   <template v-slot:main>
    <div>
      只是主要内容
    </div>
   </template>
  <template v-slot:footer>
    <p>这是底部内容</p>
  </template>
</App>
        </el-main>
      </el-container>
  </el-container>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useLoginStore } from "../store";
import App from "../components/App.vue";
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from "@element-plus/icons-vue";
const router = useRouter();
const loginStore = useLoginStore();
const data = reactive({
  add: "这是主页面传递过来的参数",
  isLoggedIn: false,
});
const toLink = () => {
  router.push({
    name: "about",
    query: {
      id: data.add,
    },
  });
};

const isCollapse = ref(true);
const handleOpen = (key, keyPath) => {
  console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
  console.log(key, keyPath);
};
const activeIndex = ref("1");
const activeIndex2 = ref("1");
const tologin = ()=>{
  router.push("/login");
}
const tooutlogin =()=>{
  loginStore.logout();
  data.isLoggedIn = loginStore.isLoggedIn;
}
onMounted(() => {
  data.isLoggedIn = loginStore.isLoggedIn;
  // console.log(data.isLoggedIn);
  // if (!data.isLoggedIn) {
  //   router.push("/login");
  // }
});
</script>
<style lang="less" scoped>
.centent {
  width: 100%;
  height: 100%;

  // background: #50b8ff;
  .el-container {
    height: 100%;
  }

  .el-header {
    border-bottom: 1px solid #44c189;
    background: #282828;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    span{
      font-size: 20px;
    }
  }

  .el-aside {
    background: #3c4043;
    height: 100%;
  }

  .el-main {
    background: #e9e9e9;
    height: 100%;
  }

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
}
</style>
